package com.it2297.main;

import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JOptionPane;
import javax.swing.UIManager;

import com.it2297.model.Customer;
import com.it2297.model.Needy;
import com.it2297.model.User;
import com.it2297.view.LoginView;

public class Main
{

	public static void main(String[] args)
	{
		try
		{
			UIManager.setLookAndFeel("com.alee.laf.WebLookAndFeel");
		}
		catch (Throwable e)
		{
			e.printStackTrace();
		}
		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					System.out.println("Loading...");
					/*
					FakeLogin fakeLogin = new FakeLogin();
					boolean isLoginSuccessful = fakeLogin.showFakeLogin();
					*/
					LoginView loginView = new LoginView();
					loginView.setVisible(true);
					/*
					if (isLoginSuccessful)
					{
						App app = new App();

						app.authenticate();

						System.out.println("App started.");
						JOptionPane.showMessageDialog(null, "Login as " + App.currentUser.getRole() + ", " + App.currentUser.getName() + ".");

						System.out.println("Customer: " + App.currentCustomer);
						System.out.println("Needy: " + App.currentNeedy);

						app.setTitle("Login as " + App.currentUser.getRole() + ", " + App.currentUser.getName() + ".");
						app.setVisible(true);
						app.addWindowListener(new WindowAdapter()
						{

							@Override
							public void windowClosing(WindowEvent e)
							{
								System.out.println("App closed.");
							}

						});

					}
					else
					{
						JOptionPane.showMessageDialog(null, "Invalid NRIC.");
						System.out.println("App closed.");
					}*/
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		});
		
	}

	/*
	@SuppressWarnings("serial")
	private static class FakeLogin extends LoginView
	{
		private String nric;

		public boolean showFakeLogin()
		{
			boolean isLoginSuccessful = false;

			try
			{
				this.nric = JOptionPane.showInputDialog("Enter NRIC:").toUpperCase();
			}
			catch (Exception ex)
			{
				System.out.println("App closed.");
				System.exit(0);
			}

			if (User.isUserExist(nric))
			{
				App.currentUser = User.getUser(nric);
				String role = App.currentUser.getRole();
				if (role.equals("ADMIN"))
				{
					// TODO NOT YET
				}
				else if (role.equals("CUSTOMER"))
				{
					App.currentCustomer = new Customer().getSingle(nric);
				}
				else if (role.equals("NEEDY"))
				{
					Needy needy = new Needy();
					needy.getSingle(nric);
					App.currentNeedy = needy;
				}
				else if (role.equals("TRAINER"))
				{
					// TODO NOT YET
				}

				isLoginSuccessful = true;
			}
			else
			{
				isLoginSuccessful = false;
			}

			return isLoginSuccessful;
		}
		
	}
	*/
}